﻿<?php
session_start();
include("gv_resist_mdl.php");
?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<?php

include("../Modules/conn.php");

$lopHP = $_SESSION["mslop"];
$ngHocGV = $_POST["date1"];
$soTietGV = $_POST["cboSoTiet"];
$ngGhiNK = date("Y-m-d");
$ndDay = $_POST["txtNDD"];

$querySel = "select * from nhat_ky where MS_LOP = '$lopHP' and NG_HOC_GV = '$ngHocGV'";
$resultSel = mysql_query($querySel, $conn) or die(mysql_error());
$count = mysql_num_rows($resultSel);

// Ngay het han cho gv ghi nhat ky
$valNgHetHanGV = strtotime($ngHocGV." +1 week");
$tgcngv = strftime("%Y-%m-%d", $valNgHetHanGV);

$tk = $_SESSION["taikhoan"];

if (strtotime($ngGhiNK) > $valNgHetHanGV) // Neu het han ghi nhat ky
{
	header("Location: ../View/gv_cpanel.php?part=nkgd&mslop=$lopHP&info=nkgdtimeout"); // Tro ve trang nhat ky giang day
}
elseif ($count > 0) // Neu da ghi nhat ky cho ngay hoc duoc chon
{
	header("Location: ../View/gv_cpanel.php?part=nkgd&mslop=$lopHP&info=nkgddup");
}
else
{
	// Ghi nhat ky
	$queryInsNKGD = "insert into nhat_ky(MSCB, MS_LOP, NG_HOC_GV, SO_TIET_GV, NG_GHI_NK, NOI_DUNG_DAY_GV, XAC_NHAN_BM, XAC_NHAN_SV)
						values ('$tk', '$lopHP', '$ngHocGV', '$soTietGV', '$ngGhiNK', '$ndDay', 'n', 'n')";
	mysql_query($queryInsNKGD, $conn) or die(mysql_error());

	mysql_close();
	header("Location: ../View/gv_cpanel.php?part=nkgd&mslop=$lopHP&info=addnkgdsucc");
}

?>